<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/7/31
  Time: 9:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>Insert title here</title>
    <script src="jq/jquery.js"></script>
</head>
<body>
    <h1 align="center">添加个人简历信息</h1>
    <div align="center">
        <form action="AddServlet" method="post">
            <table border="1px" style="background-color: darkgray">
                <tr>
                    <td>姓名：</td>
                    <td><input type="text" id="userName" name="userName"><span id="span1"></span></td>
                </tr>
                <tr>
                    <td>性别：</td>
                    <td><input type="radio" checked name="sex" value="男">男
                        <input type="radio" name="sex" value="女">女</td>
                </tr>
                <tr>
                    <td>籍贯地址：</td>
                    <td><input type="text" id="address" name="address"><span id="span2"></span></td>
                </tr>
                <tr>
                    <td>出生时间：</td>
                    <td><input type="text" id="birth" name="birth">格式：yyyy-MM-dd <span id="span3"></span></td>
                </tr>
                <tr>
                    <td>联系电话：</td>
                    <td><input type="text" name="telephone" id="telephone" onblur="judgePhone(this.value)"><span id="span"></span></td>
                </tr>
                <tr>
                    <td>毕业学校：</td>
                    <td><input type="text" id="school" name="school"><span id="span4"></span></td>
                </tr>
                <tr>
                    <td>简历状态：</td>
                    <td><input type="radio" name="status" value="1" checked>公开<input type="radio" value="0" name="status">保密</td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td><input type="submit" value="新增"><input type="button" value="返回" onclick="history.back()"></td>
                </tr>
        </table>
    </form>
    </div>
</body>

<script>
    //单击“提交”按钮提交表单
    $('form').submit(function(){
        var flag=true;
        //邮箱和密码、手机号码验证成功后提交表单
        if(!CheckUser()) flag=false;
        else if(!CheckAddress()) flag=false;
        else if(!CheckBirth()) flag=false;
        else if(!CheckTelephone()) flag=false;
        else if(!CheckSchool()) flag=false;
        return flag;
    })
    //姓名效验
    function CheckUser(){
        $('#span1').text('');
        if($('#userName').val()==""){
            $('#span1').text('姓名不能为空');
            return false;
        }
        return true;
    }
    //籍贯地址效验
    function CheckAddress() {
        $('#span2').text('');
        if($('#address').val() == ""){
            $('#span2').text('籍贯地址不能为空')
            return false;
        }
        return true;
    }
    //出生时间效验
    function CheckBirth() {
        var birth = $('#birth').val();
        $('#span3').text('');
        if(birth == ""){
            $('#span3').text('出生时间不能为空')
            return false;
        }else
        if(/^(\d{4})-(\d{2})-(\d{2})$/.test(birth) == false){
            $('#span3').text('时间格式不合法')
            return false;
        }
        return true;
    }
    //联系电话效验
    function CheckTelephone() {
        $('#span').text('');
        if($('#telephone').val() == ""){
            $('#span').text('手机号不能为空')
            return false;
        }
        return true;
    }
    //毕业学校效验
    function CheckSchool() {
        $('#span4').text('');
        if($('#school').val() == ""){
            $('#span4').text('毕业学校不能为空')
            return false;
        }
        return true;
    }

    function judgePhone(telephone){
        $.getJSON(
            'PhoneServlet',
            {phone:telephone},
            function (data) {
                if(data){
                    $("#span").text("电话号不可以使用！")
                }else{
                    $("#span").text("电话号可以使用！")
                }
            }
        )
    }
</script>
</html>
